
import javax.microedition.rms.InvalidRecordIDException;
import javax.microedition.rms.RecordComparator;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotOpenException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author FFK
 */
public class rwBC {
    
    private RecordStore rs = null;
    static final String REC_STORE = "db";
    public int[]  array ;
    public rwBC(){
        array = new int[81];
//        openRecStore();
//        readRecore();
//        closeStore();
    }

    public void doc() {
        openRecStore();
        try{
        readRecore();
        }catch(Exception e){}
        closeStore();
    }
    public void openRecStore() {
        try{
            rs = RecordStore.openRecordStore(REC_STORE, true);
        }
        catch(Exception e){
            
        }
    }

    public void writeRecore(String s) throws RecordStoreNotOpenException, RecordStoreException {
        byte[] rec = s.getBytes();
        rs.addRecord(rec, 0, rec.length);
        System.out.println(s);
    }

    public  void readRecore()  {
        int len;
        try{
            byte[] recData = new byte[50];
               for(int i = 1; i< rs.getNumRecords(); i++){
                   if(rs.getRecordSize(i) > recData.length)
                       recData = new byte[rs.getRecordSize(i)];
                   len = rs.getRecord(i, recData, 0);
                   String tam = new String(recData, 0, len);
                   array[i-1] = Integer.parseInt(tam);
                   System.out.println(array[i-1]);
               }
        }catch(Exception ex){}
    }
    public void closeStore(){
        try {
            rs.closeRecordStore();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    public void deleteStore(){
        if(RecordStore.listRecordStores() != null){
            try {
                RecordStore.deleteRecordStore(REC_STORE);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    
    
    
}


class Comparator implements RecordComparator
{
  public int compare(byte[] rec1, byte[] rec2)
  {
    String str1 = new String(rec1), str2 = new String(rec2);
    
    int result = str1.compareTo(str2);
    if (result == 0)
      return RecordComparator.EQUIVALENT;
    else if (result < 0)
      return RecordComparator.PRECEDES;
    else
      return RecordComparator.FOLLOWS;          
  }
}
